﻿using System.Collections.Generic;
using System.Web;
using Drill.Core;
using Drill.Extensibility;
using Drill.Integration.Web.Mocks;
using Drill.TestSupport;
using Drill.TestSupport.Mocks.MockDrillBits;
using NUnit.Framework;

namespace Drill.Integration.Web
{
	[TestFixture]
	public class AspNetDrillChuckDependencyResolverWithMultipleDrillBitsTests : BaseDrillBitTests
	{
		protected override IDependencyResolver GetDependencyResolverInstanceToTest()
		{
			return new AspNetDrillChuckDependencyResolver(
					new DependencyResolverInitContext
					{
						Name = "Default"
					  ,
						DrillBits = 
							new List<IDrillBit>
								{
									new AutomobileDomainMockDrillBit()
								  , new SimpleDomainAndHttpContextBaseMockDrillBit()
								}
					}
				);
		}

		[Test]
		public void CanConstructUsingConstructorWithInitializationContextArgument()
		{
			//Arrange
			// Nothing to arrange.

			// Act
			AspNetDrillChuckDependencyResolver dependencyResolver =
				new AspNetDrillChuckDependencyResolver(
					new DependencyResolverInitContext
					{
						Name = "Default"
					  , DrillBits =
							new List<IDrillBit>
								{
									new AutomobileDomainMockDrillBit()
								  , new SimpleDomainAndHttpContextBaseMockDrillBit()
								}
					}
				);

			// Assert
			Assert.That(dependencyResolver, Is.Not.Null);
		}

		[Test]
		public void CanConstructUsingConstructorWithInitializationContextAndILocatorOfHttpContextBaseArguments()
		{
			//Arrange
			// Nothing to arrange.

			// Act
			AspNetDrillChuckDependencyResolver dependencyResolver =
				new AspNetDrillChuckDependencyResolver(
					new DependencyResolverInitContext
					{
						Name = "Default"
					  ,
						DrillBits =
							new List<IDrillBit>
								{
									new AutomobileDomainMockDrillBit()
								  , new SimpleDomainAndHttpContextBaseMockDrillBit()
								}
					}
			  , new HttpContextLocator(new HttpContextMock())
				);

			// Assert
			Assert.That(dependencyResolver, Is.Not.Null);
		}

		[Test]
		public void CanGetInstanceOfHttpContextBase()
		{
			// Arrange
			IDependencyResolver dependencyResolver = GetDependencyResolverInstanceToTest();

			// Act
			HttpContextBase httpContext = dependencyResolver.GetInstance(typeof(HttpContextBase)) as HttpContextBase;

			// Assert
			Assert.That(httpContext, Is.Not.Null);
			Assert.That(httpContext, Is.AssignableFrom<HttpContextMock>());
		}

		[Test]
		public void CanGetInstanceGenericOfHttpContextBase()
		{
			// Arrange
			IDependencyResolver dependencyResolver = GetDependencyResolverInstanceToTest();

			// Act
			HttpContextBase httpContext = dependencyResolver.GetInstance<HttpContextBase>();

			// Assert
			Assert.That(httpContext, Is.Not.Null);
			Assert.That(httpContext, Is.AssignableFrom<HttpContextMock>());
		}
	}
}